package com.b.sts.controller;

import com.b.sts.entity.CommentEntity;
import com.b.sts.service.CommentService;
import com.b.sts.util.JwtUtil;
import com.b.sts.util.ResultUtil;
import com.b.sts.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评论表 前端控制器
 * </p>
 *
 * @author b
 * @since 2023-07-12
 */
@RestController
@RequestMapping("/comment")
public class CommentController {
    @Resource
    CommentService service;

    @GetMapping("/list")
    public ResultVO<List<CommentEntity>> list(CommentEntity entity) {
        List<CommentEntity> data = service.list(entity);
        return ResultUtil.success(data);
    }

    @PostMapping
    public ResultVO<Boolean> add(@RequestBody CommentEntity entity) {
        entity.setUserId(JwtUtil.getUid());
        boolean isSuccess = service.add(entity);
        return ResultUtil.autoDo(isSuccess);
    }

    @DeleteMapping("/{id}")
    public ResultVO<Boolean> del(@PathVariable Integer id) {
        boolean isSuccess = service.del(id);
        return ResultUtil.autoDo(isSuccess);
    }

    //    @GetMapping("/e/my")
    //    public ResultVO<List<CommentEntity>> my(CommentEntity entity) {
    //        entity.setUserId(JwtUtil.getUid());
    //        QueryWrapper<CommentEntity> wrapper = new QueryWrapper<>();
    //        wrapper.setEntity(entity);
    //        List<CommentEntity> data = service.list(wrapper);
    //        return ResultUtil.success(data);
    //    }
}
